package com.feng.security.controller;

import com.feng.common.api.ResponseResult;
import com.feng.security.dto.LoginBody;
import com.feng.security.service.AuthService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Feng
 * @since 2022/4/17 21:16
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    AuthService authService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public ResponseResult login(@RequestBody @Validated LoginBody loginBody) {
        return ResponseResult.success(authService.login(loginBody));
    }

    @ApiOperation("退出登录")
    @RequestMapping("/logout")
    public ResponseResult logout() {
        authService.logout();
        return ResponseResult.success();
    }

    @ApiOperation("获取当前登录的用户信息")
    @GetMapping("/info")
    public ResponseResult info() {
        return ResponseResult.success(authService.info());
    }

    @ApiOperation("获取验证码")
    @GetMapping("/code")
    public ResponseResult code() {
        return ResponseResult.success(authService.getCode());
    }
}
